<!--
 * @componentName: 
 * @待处理问题: 1.修改地址还没实现
 * @已处理问题: 
 * @Author: 舒克
 * @Official Accounts: 氧化1028
 * @email: 143587623@qq.com
 * @github: https://gitee.com/KingSio
 * @Date: 2021-03-18 19:28:27
 * @LastEditTime: 2021-03-31 10:37:50
 * @FilePath: \哇麦游戏后台\vue\1.vue全站管理系统\vue_shop\src\components\order\Order.vue
-->

<template>
    <div>
        <!-- 卡片视图区域 -->
        <SearchCommon @searchName="searchName"></SearchCommon>
        <el-card>
             <!-- 订单列表数据 -->
             <el-table :data="orderlist" border stripe>
             <el-table-column type="index"  label="#"></el-table-column>
             <el-table-column label="订单编号" prop="order_number"></el-table-column>
             <el-table-column label="订单价格" prop="order_price"></el-table-column>
             <el-table-column label="是否发货" prop="is_send"></el-table-column>
             <el-table-column label="是否付款" prop="pay_status">
                 <template slot-scope="scope">
                     <el-tag type="success" v-show="scope.row.pay_status==='1'">已付款</el-tag>
                      <el-tag type="danger" v-show="scope.row.pay_status==='0'">未付款</el-tag>
                 </template>
             </el-table-column>
             <el-table-column label="下单时间" prop="create_time"></el-table-column>
             <el-table-column label="操作" width="206px">
                 <template slot-scope="scpoe">
                     <el-button v-if="scpoe" type="primary" size="mini" icon="el-icon-edit" @click="showOrderEditBox">编辑</el-button>
                     <el-button type="success" size="mini" icon="el-icon-location" @click="showOrderProgressBox">物流进度</el-button>
                 </template>
             </el-table-column>
            
             </el-table>

             <!-- 分页区域 -->
             <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
             </el-pagination>

             <!-- 修改地址对话框 -->
 <el-dialog
      title="修改地址"
      :visible.sync="editDialogVisible"
       width="50%"
       @close="editDialogClosed"
    >
<el-form :model="editressForm" ref="editressFormRef" label-width="100px" :rules="editressFormRules">
  <el-form-item label="省市区/县" prop="editress1">
 
    <el-cascader :options="citydata" v-model="editressForm.editress1"></el-cascader>
  </el-form-item>

  <el-form-item label="详细地址" prop="editress2">
    <el-input v-model="editressForm.editress2"></el-input>
  </el-form-item>
  </el-form>
        <!-- 底部区域 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogClosed">取 消</el-button>
        <el-button type="primary" @click="addUser(title)">确 定</el-button>
      </div>

    </el-dialog>

    <!-- 展示物流进度对话框 -->
     <el-dialog
      title="物流进度"
      :visible.sync="profressDialogVisible"
       width="50%"
       @close="profressDialogClosed"
    >
<el-timeline>
    <el-timeline-item
      v-for="(activity, index) in progressInfo"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
        <!-- 底部区域 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="profressDialogClosed">取 消</el-button>
        <el-button type="primary">确 定</el-button>
      </div>

    </el-dialog>
        </el-card>
    </div>
</template>
<script>
import SearchCommon from "../common/SearchCommon2"
import {getOrderDataList,getOrderProfress} from "@/api/orderApi"
import { filterTimeData } from '@/utils/timeData'
import citydata from "../../config/citydata"
export default {
    data(){
        return {
            queryInfo:{
                query:"",//查询参数
                pagenum:1,//当前页码
                pagesize:10//显示条数
            },
            total:0,//总条数
            orderlist:[],//数据
            editDialogVisible:false,//默认修改地址对话框是隐藏

            //修改地址数据
            editressForm:{
                editress1:[],//省市区-级链选择框 
                editress2:""//详细地址
            },
            //省份数据
            citydata,
             editressFormRules: {
                editress2: [
                    { required: true, message: '请输入详细地址', trigger: 'blur' }
                ],
             },

             //物流进度对话框
             profressDialogVisible:false,
             //物流进度数据
             progressInfo:[]
        }
    },
  components: {
            SearchCommon //搜索组件
  },
  created(){
      this.getOrderList();//调用获取订单列表数据
  },
  methods: {
      /**
       * @description: 搜索的内容
       * @param {String} val
       * @return {*}
       */
      searchName(val){
          console.log(val)
      },
      //请求订单管理列表
      async getOrderList(){
          const {data:res}= await getOrderDataList(this.queryInfo);
          if(res.meta.status!==200){
              return this.$message.error("获取订单数据失败")
          }
         console.log(res)
         filterTimeData
         res.data.goods.forEach(item=>{
             item.create_time=filterTimeData(item.create_time)
         })
         this.total=res.data.total
         this.orderlist=res.data.goods
      },

      //分页-条数发送改变
      handleSizeChange(newSize){
            this.queryInfo.pagesize=newSize;
            this.getOrderList();
      },
      //分页-页码发生改变
      handleCurrentChange(newPage){
          this.queryInfo.pagenum=newPage;
           this.getOrderList();
      },

      //展示修改地址对话框
      showOrderEditBox(){
          this.editDialogVisible=true
      },
      //关闭对话框
      editDialogClosed(){
          this.$refs.editressFormRef.resetFields();//清空输入框的内容
          this.editDialogVisible=false
      },

      async showOrderProgressBox(){
          return this.$message.error("获取物流进度失败")
          let id='1106975712662';//供测试的物流单号：1106975712662(后面动态获取)
          const {data:res}=await getOrderProfress(id)
          if(res.meta.status!==200){
              return this.$message.error("获取物流进度失败")
          }
          this.progressInfo=res.data
          this.profressDialogVisible=true
      },

      //关闭物流进度对话框
      profressDialogClosed(){
           this.profressDialogVisible=false
      }
      
  },
}
</script>